﻿// -------------------------------------------------------------------------
//    @FileName         :    NFCityPlayerViewExt.h
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-17
//    @Email			:    445267987@qq.com
//    @Module           :    NFCityPlayerViewExt
//    @Desc             :
//
// -------------------------------------------------------------------------

#pragma once

#include "NFComm/NFObjCommon/NFObject.h"
#include "NFComm/NFShmStl/NFShmHashMapWithList.h"
#include "NFComm/NFShmStl/NFShmHashSet.h"
#include "NFComm/NFShmStl/NFShmList.h"
#include "NFLogicCommon/NFCommMacros.h"

class NFICityWorldObjectFunc;
class NFCityPlayer;
const uint8_t MAX_VIEW_PLAYER_NUM = 50;
const uint8_t MAX_NV_VIEW_PLAYER_NUM = 20;
const uint8_t MAX_GB_VIEW_PLAYER_NUM = 50;

const uint8_t MAX_PLAYER_ENTER_VIEW_NUM = 105;

enum enGBViewScore
{
    EN_GB_VIEW_SCORE_LV1 = 1,
    EN_GB_VIEW_SCORE_LV2 = 25,
    EN_GB_VIEW_SCORE_LV3 = 50, //off battle
    EN_GB_VIEW_SCORE_LV4 = 100, //attack range
    EN_GB_VIEW_SCORE_LV5 = 500, //team member
};

const int GB_VIEW_SPLIT_SCORE = 100;
const int DEFAULT_GB_VIEW_REFRESH_INTERNAL = 5;

typedef NFShmHashSet<uint64_t, MAX_PLAYER_ENTER_VIEW_NUM> NFCityEnterViewList;

class NFCityPlayerViewExt
{
public:
    NFCityPlayerViewExt();
    ~NFCityPlayerViewExt();
    int CreateInit();
    int ResumeInit();

public:
    int RefreshGBViewList(NFCityPlayer* pPlayer);
    void SetMaxViewNum(int iMaxNum);
    void SetGBView(bool bSet);

    int RemoveFromViewList(uint64_t ullRoleID);
    int AddToViewList(uint64_t ullRoleID, int iScore);
    bool IsInViewList(uint64_t ullRoleID);
    int IteratorViewList(NFICityWorldObjectFunc* pFunc);
    bool IsTeamLeaderInView(NFCityPlayer* pPlayer);

    int RemoveFromEnterViewList(uint64_t ullRoleID);
    int AddToEnterViewList(uint64_t ullRoleID);
    int IteratorEnterViewList(NFICityWorldObjectFunc* pFunc);

    bool IsViewListFull() const;

    bool IsEnterViewListFull();

    int GetViewLeftNum() const { return MAX_VIEW_PLAYER_NUM - m_oViewHash.size(); }

private:
    int AddNormalView(uint64_t ullRoleID, int iScore);
    int AddGBView(uint64_t ullRoleID, int iScore);

    int CalcGBViewScore(NFCityPlayer* pPlayer, NFCityPlayer* pViewPlayer, int& iAllieNum, int& iEnemyNum);

private:
    int m_iMaxViewLimit;
    NFShmHashMapWithList<uint64_t, int, MAX_VIEW_PLAYER_NUM + 5> m_oViewHash;
    NFCityEnterViewList m_oEnterViewList;

    bool m_bIsGBView;
    uint64_t m_tvGBRefreshTime;
    int m_iGBViewSplitIndex;

    uint64_t m_ullRoleId;
};
